//
//  OPNoteMainListCell.m
//  OnePiece
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPNoteMainListCell.h"

@implementation OPNoteMainListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        float height = 360 * SCREEN_WIDTH / 616;
        
        _coverImg = [[UIImageView alloc]initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH - 20, height)];
        [self.contentView addSubview:_coverImg];
        
        UIView *aa = [[UIView alloc]initWithFrame:CGRectMake(0, height - 60, SCREEN_WIDTH - 20, 60)];
        aa.backgroundColor = [UIColor blackColor];
        aa.alpha = 0.6;
        [_coverImg addSubview:aa];
        
        _picNum = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 85, 30, 50, 25)];
        _picNum.textColor = [UIColor whiteColor];
        _picNum.textAlignment = NSTextAlignmentRight;
        _picNum.shadowOffset = CGSizeMake(5, 5);
        _picNum.font = [UIFont systemFontOfSize:25];
        [self.contentView addSubview:_picNum];
        
        UILabel *pic = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 30, 44, 20, 5)];
        pic.text = @"图";
        pic.textColor = [UIColor whiteColor];
        pic.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        [self.contentView addSubview:pic];
        
        UIImageView *view = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 130, 10, 15, 15)];
        view.image = [UIImage imageNamed:@"iconfont-chakan (2)"];
        [self.contentView addSubview:view];
        
        _viewNum = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 110, 10, 35, 15)];
        _viewNum.textColor = [UIColor whiteColor];
        _viewNum.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
        [self.contentView addSubview:_viewNum];
        
        UIImageView *like = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 65, 10, 15, 15)];
        like.image = [UIImage imageNamed:@"zyciconfont-hongxin (2)"];
        [self.contentView addSubview:like];
        
        _likeNum = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 45, 10, 30, 15)];
        _likeNum.textColor = [UIColor whiteColor];
        _likeNum.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
        [self.contentView addSubview:_likeNum];
        
        _title = [[UILabel alloc]initWithFrame:CGRectMake(20, height - 45, SCREEN_WIDTH / 4 * 3 - 10, 20)];
        _title.textColor = [UIColor whiteColor];
        _title.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
        [self.contentView addSubview:_title];
        
        _userName = [[UILabel alloc]initWithFrame:CGRectMake(20, height - 25, SCREEN_WIDTH / 2, 20)];
        _userName.font = [UIFont fontWithName:@"Helvetica" size:14];
        _userName.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_userName];
        
        _ownerImg = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 60, height - 45, 40, 40)];
        _ownerImg.layer.cornerRadius = 20;
        _ownerImg.layer.masksToBounds = YES;
        [self.contentView addSubview:_ownerImg];
        
    }
    return self;
}

- (void)configureDataWithModel:(OPNoteMainListModel *)m
{
    self.picNum.text = [NSString stringWithFormat:@"%ld",m.cntP];
    if (m.viewCnt > 10000) {
        long num1 = m.viewCnt / 1000;
        long num2 = (m.viewCnt - num1 * 1000) / 100;
        self.viewNum.text = [NSString stringWithFormat:@"%ld.%ldK",num1,num2];
    }
    else
    {
        self.viewNum.text = [NSString stringWithFormat:@"%ld",m.viewCnt];
    }
    self.likeNum.text = [NSString stringWithFormat:@"%ld",m.likeCnt];
    self.title.text = m.title;
    
    [self.coverImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://img.117go.com/timg/upload/%@",m.coverpic]] placeholderImage:[UIImage imageNamed:@"beijingImg.jpg"]];
    [self.ownerImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://img.117go.com/demo27/img/ava102/%@",m.owner[@"avatar"]]]];
    self.userName.text = [NSString stringWithFormat:@"by: %@",m.owner[@"nickname"]];
}

- (void)requestDataWithModel:(OPNoteMainListModel *)m
{
    UIImageView *imageView = [[UIImageView alloc]init];
    [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://img.117go.com/timg/upload/%@",m.coverpic]]];
    CGFloat imgW = imageView.image.size.width;
    CGFloat imgH = imageView.image.size.height;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
